/**
 *  @file
 *  @brief   六边形（HEXA）梁截面属性使用解析公式计算类
 *  @author  duweixing
 *  @date    2024.04.23
 *  @version v1.0
 *  @par Copyright(c):  ShenGong  Simulation corporation
 */

#include "HexaSectionFormulaCalculator.h"
#include "DataStructure/Common/Real.h"

using SG::DataStructure::Common::Real;
using SG::DataStructure::FEM::PBARLData;
using SG::DataStructure::FEM::PBARData;
using SG::FEMSolver::Element::HexaSectionFormulaCalculator;

void HexaSectionFormulaCalculator::Compute
(
const SG::DataStructure::FEM::PBARLData& section,
_OUT SG::DataStructure::FEM::PBARData&   property,
_OUT SG::Algebra::Point&                 centroid
) const
{
    Real b1{section.m_dimension[0]};
    Real b{section.m_dimension[1]};
    Real h{section.m_dimension[2]};
    Real b2{b - 2.0 * b1};
    Real b0{b - b1};
    Real h1{0.5 * h};

    property.m_id  = section.m_id;
    property.m_mId = section.m_mId;
    property.m_A   = b0 * h;
    // Real yS = 0.0;
    // Real zS  = 0.0;
    // Real yC  = 0.0;
    // Real zC  = 0.0;
    property.m_I1  = b2 * h * h * h / 12.0 + 4.0 * (b1 * h1 * h1 * h1 / 36.0 + 0.5 * b1 * h1 * h1 * h1 / 9.0);
    property.m_I2  = h * b2 * b2 * b2 / 12.0 + 4.0 * (h1 * b1 * b1 * b1 / 36.0 +
                     0.5 * h1 * b1 * (0.5 * b2 + b1 / 3.0) * (0.5 * b2 + b1 / 3.0));
    property.m_I12 = 0.0;
    if (b0 > h)
    {
        Real beta{h / b0};
        property.m_J = b0 * h * h * h * (1.0 / 3.0 - 0.21 * beta * (1.0 - beta * beta * beta * beta / 12.0));  // ToDo
    }
    else
    {
        Real beta{b0 / h};
        property.m_J = h * b0 * b0 * b0 * (1.0 / 3.0 - 0.21 * beta * (1.0 - beta * beta * beta * beta / 12.0));
    }
    property.m_K1  = 5.0 / 6.0;  // ToDo
    property.m_K2  = 5.0 / 6.0;  // ToDo
    property.m_NSM = section.m_nsm;
    property.m_FE  = 0.0;
    property.SetStressPoints ({ 0.5 * h,  0.0,
                               -0.5 * h,  0.0,
                                0.0,      0.5 * b,
                                0.0,     -0.5 * b});
    centroid.m_x = 0.0;
    centroid.m_y = 0.0;
    centroid.m_z = 0.0;
}